package cn.wolfcode.luowowo.service.impl;

import cn.wolfcode.luowowo.api.cache.domain.ScenicRankStatisVO;
import cn.wolfcode.luowowo.api.cache.prefix.BasekeyPrefix;
import cn.wolfcode.luowowo.api.cache.prefix.ScenicPrefix;
import cn.wolfcode.luowowo.api.cache.prefix.StrategyStatisKeyPrefix;
import cn.wolfcode.luowowo.api.cache.service.IRedisService;
import cn.wolfcode.luowowo.api.cache.service.IScenicStatisRedisService;
import cn.wolfcode.luowowo.scenic.domain.Scenic;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class ScenicStatisRedisServiceImpl implements IScenicStatisRedisService {

    @Autowired
    private IRedisService redisService;


    public void setStatisVo(ScenicRankStatisVO vo) {
        redisService.set(ScenicPrefix.SCENIC_RANK_STATIS_PREFIX,vo.getScenicId()+"",vo);
    }

    public void increaseScenicStatis(Long scenicId, int synStarnum, int sceneryStarnum, int serviceStarnum, int featureStarnum) {
        ScenicRankStatisVO scenicVO = redisService.get(ScenicPrefix.SCENIC_RANK_STATIS_PREFIX, scenicId + "", ScenicRankStatisVO.class);
        scenicVO.setSynStarnum(scenicVO.getSynStarnum() + synStarnum);
        scenicVO.setSceneryStarnum(scenicVO.getSceneryStarnum() + sceneryStarnum);
        scenicVO.setServiceStarnum(scenicVO.getServiceStarnum() + serviceStarnum);
        scenicVO.setFeatureStarnum(scenicVO.getFeatureStarnum() + featureStarnum);
        redisService.set(ScenicPrefix.SCENIC_RANK_STATIS_PREFIX, scenicId + "", scenicVO);
    }

    public void addScenicCommendScore(BasekeyPrefix zsetPrefix, String key, BasekeyPrefix PrefixOfValue, Long id, int score) {
        String value = PrefixOfValue.getPrefix() + ":" + id;
        redisService.addCommonScore(zsetPrefix,key,value,score);
    }

    public List<ScenicRankStatisVO> getTopNum(BasekeyPrefix basekeyPrefix, Long id, int num) {
        List<ScenicRankStatisVO> scenicVOs = redisService.reversRange(basekeyPrefix, id + "", 0, num, ScenicRankStatisVO.class);
        return scenicVOs;
    }

    public void increaseScenicCommentStatis(Long scenicId) {
        ScenicRankStatisVO scenicVO = redisService.get(ScenicPrefix.SCENIC_RANK_STATIS_PREFIX, scenicId + "", ScenicRankStatisVO.class);
        scenicVO.setCommentnum(scenicVO.getCommentnum() + 1);
        redisService.set(ScenicPrefix.SCENIC_RANK_STATIS_PREFIX, scenicId + "", scenicVO);
    }
}
